package  
{
  import flash.display.Sprite;
  import flash.geom.Point;
	/**
   * ...
   * @author ivan
   */
  public class DragSelectionCommand implements Command
  {
    
    public function DragSelectionCommand(graphStage:GraphStage, dragPoint:Point) 
    {
      this.dragPoint = dragPoint;
      
      this.selectedItems = graphStage.selection.items.concat();
      
      redo();
    }
    
    public function undo():void
    {
      for (var i:int = 0; i < selectedItems.length; i++)
      {
        var vn:VisualNode = selectedItems[i] as VisualNode;
        if (vn)
        {
          vn.node.x -= dragPoint.x;
          vn.node.y -= dragPoint.y;
        }
      }
    }
    
    public function redo():void
    {
      for (var i:int = 0; i < selectedItems.length; i++)
      {
        var vn:VisualNode = selectedItems[i] as VisualNode;
        if (vn)
        {
          vn.node.x += dragPoint.x;
          vn.node.y += dragPoint.y;
        }
      }
    }
    
    
    private var selectedItems:Vector.<Sprite>;
    private var graphStage:GraphStage;
    private var dragPoint:Point;
    
  }

}